package com.tramy.cnpush;

import androidx.annotation.NonNull;

import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.module.annotations.ReactModule;
import com.tramy.cnpush.utils.CallBackUtils;
import com.xiaomi.mipush.sdk.MiPushClient;

@ReactModule(name = XIAOMIPushModule.NAME)
public class XIAOMIPushModule extends ReactContextBaseJavaModule {

    public static final String NAME = "XIAOMIPush";

    public XIAOMIPushModule(ReactApplicationContext reactContext) {
        super(reactContext);
    }

    @Override
    @NonNull
    public String getName() {
        return NAME;
    }

    @ReactMethod
    public void register(String appId,
                         String appKey,
                         Callback callback) {
        CallBackUtils.trustCallback(callback);
        MiPushClient.registerPush(
            getReactApplicationContext().getApplicationContext(),
            appId,
            appKey);
    }

    @ReactMethod
    public void unRegister() {
        MiPushClient.unregisterPush(
            getReactApplicationContext().getApplicationContext());
    }

}
